package fischl.log;

import java.util.HashMap;
import java.util.Map;

public final class LogFactory {
  private static Log.Provider provider = NoopLogs.provider;
  private static Map<String, Log> caches = new HashMap<>();


  public static void setProvider(Log.Provider provider) {
    LogFactory.provider = provider;
  }

  public static Log get(String name) {
    synchronized (LogFactory.class) {
      Log log = caches.get(name);
      if (log != null) return log;
      log = provider.getLog(name);
      caches.put(name, log);
      return log;
    }
  }

  public static Log get(Class<?> clazz) {
    return get(clazz.getSimpleName());
  }
}
